package mavenProject.Model;


import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name = "questions")
public class Question {
	
	@Id
	@Column(name = "questionID", insertable =false, updatable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private int id;
	
	@Column(name = "Text")
	private String question;
	
	@OneToOne
	@JoinColumn(name = "answerID")
	@Transient
	Answer rightAnswer;
	
	@OneToMany(mappedBy = "question", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
	private Set<Answer> answers;
	
	
	public Question(int id, String text, Set<Answer> answers, Answer rightAnswer){
		this.id=id;
		this.question=text;
		this.answers = answers;
		this.rightAnswer = rightAnswer;
	}
	
	public Question(){
		
	}
	
	public void setQuestion(String text){
		this.question = text;
	}
	
	public String getQuestion(){
		return this.question;
	}
	
	public void setID(int id){
		this.id = id;
	}
	
	public int getID(){
		return this.id;
	} 
	
	public void addAnswer(Answer answer){
		this.answers.add(answer);
	}
	
	public Set<Answer> getAnswers(){
		return this.answers;
	}
	
	public void setRightAnswer(Answer answer){
		this.rightAnswer = answer;
	}
	
	public Answer getRightAnswer(){
		return this.rightAnswer;
	}
	
	
}
